<?php

namespace backend\logic_pc;

use think\Db;
use external\SFTools;

class OrderLogic {
    /**
     * 获取订单列表
     * @param   string $order_number 订单号
     * @param   array  $userFind     用户对象
     * @return  array                数组列表数据
     */
    public function getOrderListBuyOrderNumber($order_number, $userFind = array() , $page , $size , $bool) {
        if (empty($userFind['user_uuid'])) {
            return SFTools::err("3300");
        }
        if (empty($userFind['fccode'])) {
            return SFTools::err("3300");
        }

        $userAuthLogic = new \backend\logic\UserAuthLogic;
        $userAuthFind = $userAuthLogic->getUserAuthListBuyFccodeAndUserUUID($userFind['fccode'], $userFind['user_uuid']);
        if(empty($userAuthFind)){
            return SFTools::err("3310");
        }
        /*if($userAuthFind['is_private'] == 1){
            $field = 'fOrdNo,fCCode,fCOrdNo,fOrdRdate,fCryCode,fOrdAllamt,fCFlag,fProNtfFlag,fOutFlag,fIfClose,fIfCancel,fCDate';
        }else{
            $field = 'fOrdNo,fCCode,fCOrdNo,fOrdRdate,fCFlag,fProNtfFlag,fOutFlag,fIfClose,fIfCancel,fCDate';
        }*/
        if(!empty($order_number)){
            $where[] = ['fOrdNo|fCOrdNo','like',$order_number.'%'];
        }
        $where[] = ['fCCode','=',$userFind['fccode']];
        if($bool){
            $returnArr['count'] = Db::table('v_ord_list')->where($where)->count();
        }
        $returnArr['list'] = Db::table('v_ord_list')->field('*')->where($where)->order('fCDate', 'desc')->limit($page,$size)->select();
        
        return $returnArr;
    }

    /**
     * 获取订单明细
     * @param   string $order_number 订单号
     * @param   array  $userFind     用户对象
     * @return  array                数组对象数据
     */
    /*public function getOrderFindBuyOrderNumber($order_number, $userFind = array()) {
        if (empty($order_number)) {
            return SFTools::err("3300");
        }
        if (empty($userFind['user_uuid'])) {
            return SFTools::err("3300");
        }
        if (empty($userFind['fccode'])) {
            return SFTools::err("3300");
        }
        $userAuthLogic = new \backend\logic\UserAuthLogic;
        $userAuthFind = $userAuthLogic->getUserAuthListBuyFccodeAndUserUUID($userFind['fccode'], $userFind['user_uuid']);
        if(empty($userAuthFind)){
            return SFTools::err("3310");
        }
        if($userAuthFind['is_private'] == 1){
            $field = 'fOrdNo,fCCode,fCOrdNo,fOrdRdate,fCryCode,fOrdAllamt,fCFlag,fProNtfFlag,fOutFlag,fIfClose,fIfCancel,fCDate';
            $field2 = 'oi.fOrdNo,oi.fSNo,oi.fGoodsID,oi.fOrdQty,oi.fOCryAmtBfDis,g.fGoodsName,g._x_f022 is_open';
        }else{
            $field = 'fOrdNo,fCCode,fCOrdNo,fOrdRdate,fCFlag,fProNtfFlag,fOutFlag,fIfClose,fIfCancel,fCDate';
            $field2 = 'oi.fOrdNo,oi.fSNo,oi.fGoodsID,oi.fOrdQty,g.fGoodsName,g._x_f022 is_open';
        }
        $order = new \backend\model\Order;
        //$field = 'fOrdNo,fCCode,fCOrdNo,fOrdRdate,fCryCode,fOrdAllamt,fCFlag,fProNtfFlag,fOutFlag,fIfClose,fIfCancel,fCDate';
        $orderFind = $order::field($field)->where('fOrdNo', $order_number)->find();
        //$field2 = 'oi.fOrdNo,oi.fSNo,oi.fGoodsID,oi.fOrdQty,oi.fOCryAmtBfDis,g.fGoodsName,g._x_f022 is_open';
        $orderFind['items'] = Db::table(DB_ERP_TABLE_PREFIX . 't_COPD_OrdItem')->field($field2)->alias('oi')->join(DB_ERP_TABLE_PREFIX . 't_BOMM_GoodsMst g', 'oi.fGoodsID = g.fGoodsID')->where('oi.fOrdNo', $orderFind['fOrdNo'])->order('fSNo', 'asc')->select();
        return $orderFind;
    }*/
}